package com.fhz.kotlin1904a

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import kotlinx.android.synthetic.main.activity_main.*
import java.util.*

class MainActivity : AppCompatActivity() {

    private var time:Int = 5

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)


//        timer.setText(time--)
        val t = Timer()
        t.schedule(object : TimerTask(){
            override fun run() {
                runOnUiThread {
                    time--
                    timer.text = time.toString()
                    if(time <= 0){
                        cancel()
                        val intent = Intent(this@MainActivity, Main2Activity::class.java)
                        startActivity(intent)
                    }
                }
            }
        },0,1000)
    }
}
